package org.example.spring.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.jsonwebtoken.Claims;
import jakarta.servlet.http.HttpServletRequest;
import org.example.spring.entity.ChattingList;
import org.example.spring.entity.Value;
import org.example.spring.mapper.ListMapper;
import org.example.spring.mapper.ValueMapper;
import org.example.spring.service.IValueService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.spring.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-05-01
 */
@Service
public class ValueServiceImpl extends ServiceImpl<ValueMapper, Value> implements IValueService {

    @Autowired
    ListMapper listMapper;
    @Autowired
    HttpServletRequest httpServletRequest;
    @Override
    public List<Value> getChatting(Integer otherId) {
        //获得当前登录ID
        String jwt = httpServletRequest.getHeader("token");
        Claims claims = JWTUtils.parseJWT(jwt);
        Integer currentId = claims.get("id", Integer.class);
        QueryWrapper queryWrapper=new QueryWrapper<>().eq("user_id",currentId).eq("other_id",otherId);

        ChattingList chattingList = listMapper.selectOne(queryWrapper);
        QueryWrapper queryWrapper1=new QueryWrapper<>().eq("value_id",chattingList.getValueId());
        List<Value> values = list(queryWrapper1);
        return values;
    }
}
